<?php

/**
 * 小说模型
 */
namespace backend\models\novel;

use Yii;
use yii\db\ActiveRecord;
use yii\data\Pagination;
use yii\data\ArrayDataProvider;

class NovelChapter extends ActiveRecord
{
    /**
     * 获取novel列表
     */
    public function getChapterList( $params = array() )
    {
        $data = array(
            'list' => array(),
            'count' => 0,
        );
        $novel = self::find();
        $novel->select('*');
        
        if(isset($params['ids']) && is_array($params['ids'])){
            $ids = implode(',',$params['ids']);
            $novel->andWhere("chapter_id in ({$ids})");
        }else{
            $page = $params['page'];
            $offset = 0;
            $limit = $params['pageSize'];
            if($page > 0){
                $offset = ($page - 1) * $limit;
            }
            $count = $novel->count();
            $novel->offset($offset)->limit($limit);
        }
        $result = $novel->asArray()->all();
        $data['list'] = $result ? $result : array();
        $data['count'] = isset($count) ? $count : 0;
        return $data;
    }
}

